package com.nf.health.app.adapter;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.activity.my.impl.MyContact;
import com.nf.health.app.models.DeviceData;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

public class MemberAdapter extends BaseAdapter {
	private Activity context;
	private List<DeviceData> datas;
	private String type;
	public MemberAdapter(Activity context, List<DeviceData> datas,String type) {
		this.context = context;
		this.datas = datas;
		this.type = type;
	}
	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_member_data, position);
		DeviceData dataItem = datas.get(position);

		ImageView iv_data_iconId = holder.getView(R.id.iv_data_iconId);
		holder.setText(R.id.tv_data_oneId, dataItem.getDeviceName());
		holder.setText(R.id.te_date_check, dataItem.getDeviceDataDesc());
		if(type.equals("oldMobile")){
			if(position == 2){
				ImageLoaderUtils.getinstance(context).getImage(iv_data_iconId,"",R.drawable.old_persona_zuji);
				holder.setText(R.id.tv_data_oneId,"运动轨迹");
				holder.setText(R.id.te_date_check,"老人最近的运动轨迹");
			}else{
				ImageLoaderUtils.getinstance(context).getImage(iv_data_iconId, dataItem.getDeviceImage(),R.drawable.ic_launcher);
			}
		}else if(dataItem.getDeviceType().equals(MyContact.DEVICE_TYPE_SICK_FLAG) || dataItem.getDeviceType().equals(MyContact.DEVICE_TYPE_SHOW_OLD_FLAG)){
			holder.setText(R.id.tv_data_oneId, dataItem.getDeviceName());
			holder.getView(R.id.te_date_check).setVisibility(View.GONE);

			((LinearLayout)holder.getView(R.id.ll_device_data_and_health)).setGravity(Gravity.CENTER_VERTICAL);
			((TextView)holder.getView(R.id.tv_data_oneId)).setGravity(Gravity.CENTER_VERTICAL);
			ImageLoaderUtils.getinstance(context).getImage(iv_data_iconId, dataItem.getDeviceImage(),R.drawable.iv_heathy_manager_pro);
		}else{
			ImageLoaderUtils.getinstance(context).getImage(iv_data_iconId, dataItem.getDeviceImage(),R.drawable.ic_launcher);
		}
		return holder.getConvertView();
	}
	public  void  notifyMyDeviceDataChanged(List<DeviceData> datas,String type) {
		this.datas = datas;
		this.type = type;
		notifyDataSetChanged();
	}
}
